import xlrd
import urllib.request
import time
import os
path = os.path.dirname(os.getcwd())
class Server:
    def get_server(self):
        """获取serverlist表中的数据，返回list列表"""
        server = xlrd.open_workbook(f"{path}\\config\\serverlist.xlsx")
        server_sheet = server.sheet_by_name("server")
        server_list = []
        for a in range(1,server_sheet.nrows):
            server_list.append(server_sheet.row_values(a))
        return server_list

    def output(self):
        """输出打印服务器列表选项"""
        s = Server()
        for a in s.get_server():
            print(f"{str(int(a[0]))}： {a[2]}")

class Other_Methods:
    def get_serverid(self):
        """根据输入1234的选项返回要使用的服务器地址（可能是ip可能是域名）"""
        id = str(input("输入要使用的服务器ID(输入1234选项即可):"))
        s = Server()
        serverip = ""
        for a in s.get_server():
            if id == str(int(a[0])):
                serverip = a[1]
                break
        return serverip
    def read(self):
        """返回需要批量使用的UID"""
        x = xlrd.open_workbook(f"{path}\\config\\UserUID.xlsx")
        s = x.sheet_by_name("UID")
        return s.col_values(0,1)

class Super_God:
    def __init__(self,ip,id):
        self.ip = ip
        self.id = id
    def GM(self):
        """一键超神"""
        urllib.request.urlopen(f"http://{self.ip}:8061/gmexec?type=2&userid={self.id}&mkind=4&num=10000",) #添加金星10000
        time.sleep(0.2)
        urllib.request.urlopen(f"http://{self.ip}:8061/gmexec?type=12&userid={self.id}&num=3")#添加对局数
        time.sleep(0.2)
        urllib.request.urlopen(f"http://{self.ip}:8061/gmexec?type=5&userid={self.id}&cup=1000&occ=1")#加奖杯数1000
        time.sleep(0.2)
        urllib.request.urlopen(f"http://{self.ip}:8061/gmexec?type=24&userid={self.id}&all=1")#全身份解锁
        time.sleep(0.2)
    def Storm_Troops(self):
        pass
    def gift(self):
        """批量添加礼物"""
        x = xlrd.open_workbook(f"{path}\execl\\object.xlsx")
        s = x.sheet_by_name("gift")
        for a in s.col_values(0,1):
            time.sleep(0.2)
            print(f"添加礼物：{str(int(a))}")
            urllib.request.urlopen(f"http://{self.ip}:8061/gmexec?type=1&userid={self.id}&itemid={str(int(a))}")
    def objects(self):
        """批量添加其他页签种的所有道具，如果没有数据返回空"""
        x = xlrd.open_workbook(f"{path}\execl\\object.xlsx")
        s = x.sheet_by_name("其他")
        if len(s.col_values(0,1)) == 0:
            print("表种没有可以添加的道具ID，请输入正确的道具ID")
            return 
        else:
            for a in s.col_values(0,1):
                urllib.request.urlopen(f"http://{self.ip}:8061/gmexec?type=1&userid={self.id}&itemid={str(int(a))}&num=1")



            
    








